package com.zfk.framework.variable_handling;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map;
public class GlobalVariablePool {
    private static final Logger logger = LogManager.getLogger(GlobalVariablePool.class);
    private static final ConcurrentHashMap<String, Object> globalVariablePool = new ConcurrentHashMap<>();
    //存储变量到变量池
    public static void putIntoVariablePool(String key, Object value) {
        globalVariablePool.put(key, value);
    }

    //获取变量
    public static Object getFromVariablePool(String key) {
        logger.info("从全局变量池获取变量 " + key);
        return globalVariablePool.get(key);
    }
    //清空变量池
    public static void clearVariablePool() {
        logger.info("清空全局变量池");
        globalVariablePool.clear();
    }

    //初始化变量池
    public static void initialize(Map<String, Object> initialVariables) {
        logger.info("初始化全局变量池: {}", initialVariables);
        if (initialVariables != null) {
            globalVariablePool.putAll(initialVariables);
        }
    }
    //接下来需要分别去处理 CaseData中 String字段和  Map字段里的 //{{variable}}，参考 VariableReplace.java
}
